﻿// <copyright file="EasyWebApp.cs" company="<Customer Name>">This is a "work-for-hire". or Copyright (C) 2010 MicroCODE Incorporated Troy, MI</copyright><author><Class Author's Name></author>

using System.Collections;
using System.Collections.Specialized;
using System.Data;
using Org.EasyWeb.DataAccess;
/*
 *      Title:    <Class Description>
 *      Module:   ClassTemplate (<Namespace>:ClassTemplate.cs)
 *      Project:  <Project Name>
 *      Customer: <Customer Name>
 *      Facility: MicroCODE Incorporated
 *      Date:     <Class Creation Date>
 *      Author:   <Class Author's Name>
 * 
 * 
 * 
 *  
 *      MODIFICATIONS:
 *      --------------
 *
 *  Date:         By-Group:   Rev:     Description:
 *
 *  DD-Mmm-YYYY   XYZ-GROUP  {0001}    Describe reason for creating or modifying class... 
 * 
 * 
 * 
 */
using Org.EasyWeb.Sys;

namespace Org.EasyWeb.Data
{
    public abstract class WebSimpleUpdateDataSet : UpdateDataSet, IXmlHttpPost2Page, IXml2Page, IHttpGet2Page, IListEvent
    {
        // Fields
        private Hashtable fCodeTables;
        private TableSelector fSelector;

        // Events
        public event FilledCustomEventHandler FilledCustomTables;

        public event FilledListEventHandler FilledListTables;

        // Methods
        protected WebSimpleUpdateDataSet()
        {
        }

        protected abstract void FillCustomTables(bool isPost, string operation, NameValueCollection queryString, DataSet postDataSet);
        public virtual string GetAlertString(PageStyle style, string operation, NameValueCollection queryString, DataSet postDataSet)
        {
            return string.Empty;
        }

        public abstract string GetDefaultPage(bool isPost, PageStyle style, string operation, PageX pageX, string retURL);
        public virtual string GetJScript(PageStyle style, string operation)
        {
            return string.Empty;
        }

        public abstract string GetXsltFile(bool isIe, PageStyle style, string operation);
        protected virtual void NavigateData(PageStyle style)
        {
        }

        protected virtual void OnFilledCustomTables(FilledCustomEventArgs e)
        {
            if (this.FilledCustomTables != null)
            {
                this.FilledCustomTables(this, e);
            }
        }

        protected virtual void OnFilledListTables(FilledListEventArgs e)
        {
            if (this.FilledListTables != null)
            {
                this.FilledListTables(this, e);
            }
        }

        public virtual string Post(PageStyle style, string operation, NameValueCollection queryString, DataSet postDataSet)
        {
            this.SetData(true, operation, queryString, postDataSet);
            return null;
        }

        protected virtual void ProcessCodeTables(PageStyle style)
        {
        }

        private void SetData(bool isPost, string operation, NameValueCollection queryString, DataSet postDataSet)
        {
            this.FillCustomTables(isPost, operation, queryString, postDataSet);
            this.OnFilledCustomTables(FilledCustomEventArgs.GetArgs(isPost, operation, queryString, postDataSet));
            if (!isPost)
            {
                this.NavigateData(PageStyle.Custom);
                this.ProcessCodeTables(PageStyle.Custom);
            }
        }

        public void SetData(bool isPost, PageStyle style, string operation, NameValueCollection queryString)
        {
            this.SetData(false, operation, queryString, null);
        }

        // Properties
        protected Hashtable CodeTables
        {
            get
            {
                if (this.fCodeTables == null)
                {
                    this.fCodeTables = new Hashtable();
                }
                return this.fCodeTables;
            }
        }

        protected TableSelector Selector
        {
            get
            {
                if (this.fSelector == null)
                {
                    this.fSelector = new TableSelector(this);
                }
                return this.fSelector;
            }
        }
    }
}
